//余额表动态列

var columns = function(mode, showYear){
    var cols = [{
        title:'科目编码',
        field:'buname',
        align:'left',
        width:100,
        className:'bdr'
    }, {
        title:'科目名称',
        field:'buname',
        width:'auto',
        className:'bdl'
    }];

    var initBalance = {
        title:'方向',
        width:50,
        field:'',
        content:'借',
        className:'bdl'
    }

    var endBalance = {
        title:'方向',
        width:50,
        field:'',
        content:'借',
    }

    //数量金额式
    if(mode == '1'){
        cols = cols.concat([
            initBalance, {
                title:'期初余额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, {
                title:'本期借方发生',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, {
                title:'本期贷方发生',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, showYear ? {
                title:'本年借方累计',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            } : null, showYear ? {
                title:'本年贷方累计',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            } : null, endBalance, {
                title:'期末余额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }
        ])
    }

    //外币金额式
    else if(mode == '2'){
        cols = cols.concat([
            initBalance, {
                title:'期初余额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, {
                title:'本期借方发生',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, {
                title:'本期贷方发生',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, showYear ? {
                title:'本年借方累计',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            } : null, showYear ? {
                title:'本年贷方累计',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            } : null, endBalance, {
                title:'期末余额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'金额',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }
        ])
    }

    //数量外币式
    else if(mode == '2'){
        cols = cols.concat([
            initBalance, {
                title:'期初余额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, {
                title:'本期借方发生',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, {
                title:'本期贷方发生',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }, showYear ? {
                title:'本年借方累计',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            } : null, showYear ? {
                title:'本年贷方累计',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            } : null, endBalance, {
                title:'期末余额',
                field:'buname',
                className:'bdlr',
                children:[{
                    title:'数量',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }, {
                    title:'外币',
                    field:'buname',
                    align:'right',
                    className:'bdtlr'
                }]
            }
        ])
    }

    //金额式
    else{
        cols = cols.concat([{
            title:'期初余额',
            field:'buname',
            className:'bdlr',
            children:[{
                title:'借方',
                field:'buname',
                align:'right',
                className:'bdtlr'
            }, {
                title:'贷方',
                field:'buname',
                align:'right',
                className:'bdtlr'
            }]
        }, {
            title:'本期发生',
            field:'buname',
            className:'bdlr',
            children:[{
                title:'借方',
                field:'buname',
                align:'right',
                className:'bdtlr'
            }, {
                title:'贷方',
                field:'buname',
                align:'right',
                className:'bdtlr'
            }]
        }, showYear ? {
            title:'本年累计',
            field:'buname',
            className:'bdlr',
            children:[{
                title:'借方',
                field:'buname',
                align:'right',
                className:'bdtlr'
            }, {
                title:'贷方',
                field:'buname',
                align:'right',
                className:'bdtlr'
            }]
        } : null, {
            title:'期末余额',
            field:'buname',
            className:'bdlr',
            children:[{
                title:'借方',
                field:'buname',
                align:'right',
                className:'bdtlr'
            }, {
                title:'贷方',
                field:'buname',
                align:'right',
                className:'bdtlr'
            }]
        }])
    }

    var count = 0, width;
    Nui.each(cols, function(v){
        if(v && v.children){
            count++
        }
    })

    if(count === 3){
        width = 22
    }
    else if(count === 4){
        width = 18
    }
    else if(count === 6){
        width = 12
    }

    var _cols = [];
    Nui.each(cols, function(v){
        if(v){
            if(v.children){
                v.width = width+'%';
                Nui.each(v.children, function(_v){
                    _v.width = width/2 + '%';
                })
            }
            _cols.push(v)
        }
    })

    return _cols
}

return columns